//
//  DB_BaseViewModel.m
//  RacMVVM
//
//  Created by 崔博 on 2018/11/23.
//  Copyright © 2018年 崔博. All rights reserved.
//

#import "DB_BaseViewModel.h"

@interface DB_BaseViewModel()

@property (nonatomic, strong, readwrite) id<DB_BaseViewModelProtocol> services;
@property (nonatomic, copy, readwrite) NSDictionary *params;
@property (nonatomic, strong, readwrite) RACSubject *errors;
@property (nonatomic, strong, readwrite) RACSubject *willDisappearSignal;

@end
@implementation DB_BaseViewModel

+ (instancetype)allocWithZone:(struct _NSZone *)zone
{
    DB_BaseViewModel * viewModel = [super allocWithZone:zone];
    @weakify(viewModel)
    [[viewModel rac_signalForSelector:@selector(initWithService:parms:)] subscribeNext:^(id x) {
       @strongify(viewModel)
        [viewModel initialize];
    }];
    
    return viewModel;
}

- (instancetype)initWithService:(id<DB_BaseViewModelProtocol>)service parms:(NSDictionary *)parms
{
    if (self == [super init]) {
        self.title    = parms[@"title"];
        self.services = service;
        self.params   = parms;
        self.shouldRequestRemoteDataOnViewDidLoad = YES;
    }
    return self;
}
- (void)initialize {};
#pragma mark - lazy
- (RACSubject *)errors {
    if (!_errors) _errors = [RACSubject subject];
    return _errors;
}
- (RACSubject *)willDisappearSignal {
    if (!_willDisappearSignal) _willDisappearSignal = [RACSubject subject];
    return _willDisappearSignal;
}

@end
